import graphics
# -*- encoding: utf-8 -*-

import scene
import config
import map

from sp_player import Player
from sp_wall import Wall
from gp_solid import GSolid
from sp_spinedown import SpineDown
from sp_spineup import SpineUp
from sp_tilegreen import TileGreen
from sp_tilered import TileRed
from sp_tileyellow import TileYellow
from sp_tilepink import TilePink
from sp_tileturquoise import TileTurquoise
from sp_tileorange import TileOrange
from sp_tileviolet import TileViolet
from sp_tile_end import TileEnd
from sp_tile_start import TileStart


class SceneHome(scene.Scene):
    """Escena inicial del juego, esta es la primera que se carga cuando inicia"""

    def __init__(self, director,):
        scene.Scene.__init__(self, director)
        self.back = graphics.load_image(config.backs+"fondo.png")
        self.player = Player("player.png", 1, 1)
        self.map = map.Map("pruebas.tmx")

        self.g_solid = GSolid()

        h = 0
        w = 0
        for f in range(self.map.height):
            w = 0
            for c in range(self.map.width):

                if self.map.layer[f][c] == 1:
                    sprite = TileGreen(self.map.tileset[1], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 2:
                    sprite = TileRed(self.map.tileset[2], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 3:
                    sprite = Wall(self.map.tileset[3], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 4:
                    sprite = TileYellow(self.map.tileset[4], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 5:
                    sprite = TilePink(self.map.tileset[5], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 6:
                    sprite = TileTurquoise(self.map.tileset[6], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 7:
                    sprite = TileOrange(self.map.tileset[7], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 8:
                    sprite = TileViolet(self.map.tileset[8], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 17:
                    sprite = TileEnd(self.map.tileset[17], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 18:
                    sprite = TileStart(self.map.tileset[18], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 19:
                    sprite = SpineDown(self.map.tileset[19], (w, h), 1)
                    self.g_solid.add(sprite)
                elif self.map.layer[f][c] == 20:
                    sprite = SpineUp(self.map.tileset[20], (w, h), 1)
                    self.g_solid.add(sprite)
                w += 16
            h += 16


    def on_update(self):
        pass

    def on_event(self):
        pass

    def on_draw(self, screen):
        screen.blit(self.back, (0, 0))
        self.g_solid.draw(screen)
        self.player.draw(screen)